<script setup>
import {useUserStore} from "@/stores/user.js";
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
const userStore = useUserStore()
import {useRouter} from "vue-router";

const router = useRouter();

router.beforeEach((to, from, next) => {
  if (userStore.user === null || userStore.user.id === undefined && to.path !== '/login') {
    if (to.path !== '/login') {
      next('/login');
    } else {
      next(); // 继续导航
    }
  } else {
    next(); // 继续导航
  }
});


// router.beforeEach( (to) => {
//   // console.log('我是app.vue')
//   console.log(userStore.user)
//   // console.log(userStore.user.id)
//   console.log("我是路径")
//   console.log(to.path)
//
//   if (userStore.user === null || userStore.user.id === undefined  && to.path !== '/login') {
//     return ('/login');
//   }
//   return;
// })

</script>

<template>
  <div id="App">
    <div>
      <!-- App.vue只需要留一个路由出口 router-view即可 -->
      <el-config-provider :locale="zhCn">
        <router-view></router-view>
      </el-config-provider>
    </div>
  </div>
</template>

<style>
#App {
}
body{
  margin: 0px !important;
}
</style>
